﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace RWLib
{
    public class AlwaysReachableQuery: Query
    {

        private Formula condition;

        public AlwaysReachableQuery(Tree _tree, Formula _cond)
        {
            condition = _cond;
            tree = _tree;
        }

        public override bool Run()
        {
             List<Node> children=tree.Root.Nodes;
             List<Node> nodes = children;
             while (children.Count>0) {
                 nodes = children;
                 children = children.Select(c=>c.Nodes).SelectMany(c=>c).ToList();
             }
             return !nodes.Any(c=>!condition.Eval(c.Fluents));
        }
    }
}
